﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.iss.inventory.Entity;

namespace Staionery_Inventory.Presentation.Reports
{
    public partial class re_order_report : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["empID"] == null)
            {
                Response.Redirect("~/Presentation/login.aspx");
            }
            Label lbl = this.Master.FindControl("lblLogInName") as Label;
            if (lbl != null)
            {
                lbl.Text = Session["UserName"].ToString();
            }

        }

        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            List<object> list = new List<object>();
            InvManagementEntities inventent = new InvManagementEntities();
            string selectedMonth = DropDownList1.SelectedValue;
            int month = Convert.ToInt32(selectedMonth);
            DateTime selectedDateTime = new DateTime(2014, month, 1);
            DateTime startDate = new DateTime(2014, month, 1);
            DateTime endDate = new DateTime();
            var thisMonthStart = startDate.AddDays(1 - selectedDateTime.Day);
            startDate = Convert.ToDateTime(thisMonthStart);
            var thisMonthEnd = thisMonthStart.AddMonths(1).AddSeconds(-1);
            endDate = Convert.ToDateTime(thisMonthEnd);
            var t = from inv in inventent.StationeryItems
                    join c in inventent.PurchaseOrderDetails on inv.ItemID equals c.ItemID
                    join q in inventent.PurchaseOrders on c.PurchaseID equals q.PurchaseID
                    where (q.DateRequired >= startDate && q.DateRequired <= endDate) && (inv.QtyLeft <= inv.ReorderLevel)

                    select new { inv.ItemID, inv.Description, inv.QtyLeft, inv.ReorderLevel, inv.ReorderQty, q.PurchaseID, q.DateRequired };
            list = t.ToList<object>();
            gvShow.DataSource = list;
            gvShow.DataBind();
        }
    }
}